package weifei.live.simulation.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import weifei.live.simulation.entity.TradeArea;
import weifei.web.Result;

@RestController
@RequestMapping("/adminer")
public class TradeAreaAdminerController
{

    @Autowired
    private TradeArea dao_trade_area;


    @PostMapping("/addTradeArea")
    public Result addTradeArea(@Valid @RequestBody TradeArea tradeArea)
    {
        QueryWrapper<TradeArea> qw_trade_area = new QueryWrapper<>();
        qw_trade_area.eq(TradeArea.Column.Name.getName(), tradeArea.getName());
        var ta = this.dao_trade_area.selectOne(qw_trade_area);
        if (ta != null)
            return Result.failed("已存在同名商圈");
        if (!tradeArea.insert())
            return Result.exception("创建失败，数据库出错");
        return Result.success("创建成功");
    }


}

